<?php

namespace app\user\controller\mall\shop;

use app\common\controller\Userend;

/**
 * 快递报价
 *
 * @icon fa fa-circle-o
 */
class Freightprice extends Userend
{
    /**
     * Freightprice模型对象
     * @var \app\common\model\mall\shop\Freightprice
     */
    protected $model = null;
    protected $freightId = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\common\model\mall\shop\Freightprice;
        $this->freightId = $this->request->param("freight_id/d");
        $this->assignconfig("freight_id", $this->freightId);
    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);

        if ($this->request->isAjax())
        {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField'))
            {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->where(["freight_id"=>$this->freightId])
                ->where($where)
                ->count();

            $list = $this->model
                ->where(["freight_id"=>$this->freightId])
                ->where($where)
                ->order($sort, $order)
                ->select();
            $list = collection($list)->toArray();

            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }

    public function add(){
        $freight_id = $this->request->param('freight_id');
        $this->assign("freightId", $freight_id);
        return parent::add();
    }
}
